package top.huxy.boot.model.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import top.huxy.boot.model.dto.DTOBlog;

import java.util.Date;

/**
 * @author huxy
 * @date 2021-08-28
 **/
@Data
@NoArgsConstructor
public class Blog {

    private Integer id;

    /**
     * 文章标题
     **/
    private String title;

    /**
     * 文章描述Markdown
     **/
    private String description;

    /**
     * 文章内容Markdown
     **/
    private String content;

    /**
     * 是否私有
     **/
    private Boolean isPrivate;

    /**
     * 是否已删除
     **/
    private Boolean isDel;

    /**
     * 是否需要密码访问
     **/
    private Boolean isProtected;

    /**
     * 文章密码
     **/
    private String password;

    /**
     * 能否评论
     **/
    private Boolean commentAble;

    /**
     * 能否赞赏
     **/
    private Boolean appreciationAble;

    /**
     * 外键,发布者id
     **/
    private Integer publisherId;

    /**
     * 是否置顶
     **/
    private Boolean isTop;

    /**
     * 浏览次数
     **/
    private Integer views;

    /**
     * 文章封面
     **/
    private String fm;

    private long createTime;

    private Date updateTime;

    public Blog(String title, String description, String content, Boolean isPrivate, Boolean isProtected, String password, Boolean commentAble, Boolean appreciationAble, Integer publisherId, Boolean isTop, String fm, long createTime) {
        this.title = title;
        this.description = description;
        this.content = content;
        this.isPrivate = isPrivate;
        this.isProtected = isProtected;
        this.password = password;
        this.commentAble = commentAble;
        this.appreciationAble = appreciationAble;
        this.publisherId = publisherId;
        this.isTop = isTop;
        this.fm = fm;
        this.createTime = createTime;
    }

    public Blog(DTOBlog dtoBlog, int adminId) {
        this(dtoBlog.getTitle(),
                dtoBlog.getDescription(),
                dtoBlog.getContent(),
                dtoBlog.getIsPrivate(),
                dtoBlog.getIsProtected(),
                dtoBlog.getPassword(),
                dtoBlog.getCommentAble(),
                dtoBlog.getAppreciationAble(),
                adminId,
                dtoBlog.getIsTop(),
                dtoBlog.getFm(), System.currentTimeMillis()
        );
    }
}
